/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ftpdownload;

import java.io.File;

/**
 *
 * @author A7med Kotb
 */
public class UtilityClass {

    private String fileToDelete;
    private String oldF;
    private String newF;

    public UtilityClass(String fileToDelete) {
        this.fileToDelete = fileToDelete;
        deletefile(fileToDelete);
    }

    public UtilityClass(String oldF, String newF) {
        this.oldF = oldF;
        this.newF = newF;
        renameFile(oldF, newF);
    }

    //Delete ZIP file
    public void deletefile(String file) {
        String correctPath = file.replace("\\", "/");
        System.out.println(" Old File To be Deleted " + file);
        System.out.println(" New File To be Deleted " + correctPath);
        File f1 = new File(correctPath);
        boolean success = f1.delete();
        if (!success) {
            LogFile.log(" System ", " Failed to Delete the File [" + file + "]");
            System.out.println("Deletion failed.");
        } else {
            LogFile.log(" System ", " Successfully Deleted the Downloaded File[" + file + "] After Renaming it");
            System.out.println("File deleted.");
        }
    }

    //Rename File
    public void renameFile(String oldf, String newf) {
        File file = new File(oldf);
        File file2 = new File(newf);
        boolean success = file.renameTo(file2);
        if (!success) {
            System.out.println("File was not successfully renamed");
            LogFile.log(" System ", " Failed to Rename the File [" + oldf + "]");
        } else {
            System.out.println("File was successfully renamed");
            LogFile.log(" System ", " Successfully Renamed the Downloaded File[" + oldF + "] to be ["+newF+"]");
        }
    }
}
